﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XO
{
    class Program
    {
        enum CellValue
        {
            Empty,
            X,
            O,
        }

        static void Main(string[] args)
        {
         
            CellValue[] table = new CellValue[9]
                { 
                    CellValue.Empty, CellValue.Empty, CellValue.Empty,
                    CellValue.Empty, CellValue.Empty, CellValue.Empty,
                    CellValue.Empty, CellValue.Empty, CellValue.Empty
                };

            var currentTurn = GenerateXorZero();
            SayHello(currentTurn);
            GrabTurn();
        }

        static CellValue GenerateXorZero()
        {
            if(DateTime.Now.Second % 2 == 0)
            {
                return CellValue.X;
            }
            else
            {
                return CellValue.O;
            }
        }

        static void SayHello(CellValue currentTurn)
        {
            Console.WriteLine("Hello, it`s player {0} turn", currentTurn);
        }

        static int GrabTurn()
        {
            Console.WriteLine("Use digits from 1 to 9 to put your symbol into a field, according to NumPad layout");
            while (true)
            {
                var turnIndex = 0;
                var grabbedIndex = 0;
                var grabbedIndexString = Console.ReadLine();
                bool tryParseResult = int.TryParse(grabbedIndexString, out grabbedIndex);
                if(tryParseResult)
                {
                    
                    if(grabbedIndex > 0 && grabbedIndex < 10)
                    {
                        return turnIndex;
                    }
                    else
                    {
                        Console.WriteLine("Please use digits from 1 to 9");
                    }
                }
                
                else
                {
                    Console.WriteLine("Please use digits from 1 to 9");
                }
            }
           
        }
    }
}
